/*
 * PosCase.cpp
 *
 *  Created on: 2012-9-8
 *      Author: yangentao@gmail.com
 */

#include "Test.h"

#include "../ed/Pos.h"


TEST(Pos, ref){
	PosManager pm;
	Pos p0 = pm.createPos(0);
	Pos p1 = pm.createPos(1);
	Pos p2 = p0;
	Pos p3 = p0;

	EXPECT_EQ(pm.size(), 2);
	p0.release();
	p1.release();
	EXPECT_EQ(pm.size(), 1);
	p2.release();
	EXPECT_EQ(pm.size(), 1);

	p3.release();
	EXPECT_EQ(pm.size(), 0);
}

TEST(Pos, createPos){
	PosManager pm;
	Pos p0 = pm.createPos(0);
	Pos p1 = pm.createPos(1);
	Pos p2 = pm.createPos(2);
	Pos p3 = pm.createPos(3);

	Pos p4 = p3;

	pm.onTextReplaced(1,String(' ', 2), String(' ', 1));//

	EXPECT_EQ(p0.index(), 0)<<"  "<<p0.index();
	EXPECT_FALSE(p1.isValid())<<"  "<<p1.index();
	EXPECT_FALSE(p2.isValid())<<"  "<<p2.index();

	EXPECT_EQ(p3.index(), 2)<<"  "<<p3.index();
	EXPECT_EQ(p4.index(), 2)<<"  "<<p4.index();

}


